package org.zoomdev.zoom.dao.adapters.result;

import org.zoomdev.zoom.common.caster.ValueCaster;
import org.zoomdev.zoom.dao.adapters.ResultSetAdapter;

import java.sql.ResultSet;
import java.sql.SQLException;

public class WrapDataAdapterResultSetAdapter implements ResultSetAdapter {
    private final ValueCaster adapter;

    private final ResultSetAdapter resultSetAdapter;

    public WrapDataAdapterResultSetAdapter(ValueCaster adapter, ResultSetAdapter resultSetAdapter) {
        this.adapter = adapter;
        this.resultSetAdapter = resultSetAdapter;
    }

    @Override
    public Object getObject(ResultSet rs, int columnIndex) throws SQLException {
        Object value = resultSetAdapter.getObject(rs, columnIndex);
        return adapter.to(value);
    }
}
